package mq

import (
	"charging_pile/util/protocol/jiuxing"

	"github.com/zeromicro/go-zero/core/logx"
)

func handle40(nc *natsClient, in *jiuxing.Package) (jxMsg *jiuxing.Package) {
	msg := jiuxing.Msg40{}
	msg.Decode(in.Payload)
	logx.Infof("msg40:%+v", msg)

	defer func() {
		resp := jiuxing.Msg41{}
		jxMsg = &jiuxing.Package{
			Cmd:        byte(0x41),
			Sn:         in.Sn,
			Encryption: in.Encryption,
			PackageLen: 0,
			Payload:    []uint8{},
			Check:      0,
		}
		resp.Tm = formatJxTime()
		resp.Vin = msg.Vin
		resp.Balance = 1000000
		resp.AllowCharge = 1
		resp.RefuseReason = 0
		resp.BillMode = 1
		jxMsg.Payload = resp.Encode()
		jxMsg.PackageLen = uint16(len(jxMsg.Payload))
	}()

	return nil
}

func init() {
	HandlerMap[uint8(0x40)] = handle40
}
